#!/usr/bin/env node

const { execSync } = require('child_process');
const path = require('path');

// 获取命令行参数
const args = process.argv.slice(2);
const mode = args[0] || 'production';

console.log(`🚀 开始构建 ${mode} 环境...`);

try {
  // 根据环境执行不同的构建命令
  let buildCommand;
  switch (mode) {
    case 'test':
      buildCommand = 'npm run build:test';
      break;
    case 'staging':
      buildCommand = 'npm run build:staging';
      break;
    case 'production':
    case 'prod':
      buildCommand = 'npm run build:prod';
      break;
    default:
      console.error(`❌ 不支持的环境: ${mode}`);
      console.log('支持的环境: test, staging, production');
      process.exit(1);
  }

  console.log(`📦 执行构建命令: ${buildCommand}`);
  execSync(buildCommand, { stdio: 'inherit' });

  console.log(`✅ ${mode} 环境构建完成!`);
  console.log(`📁 输出目录: ${path.resolve(process.cwd(), 'dist')}`);
} catch (error) {
  console.error(`❌ 构建失败:`, error.message);
  process.exit(1);
}
